#include <iostream>
/*this指针指向当前对象
谁调用这个函数这个就指向谁*/
class Person
{
public:
    Person(int age) : age(age) {}
    Person() : age(0) {}
    int getAge()
    {
        /*好像没区别-》》》》》》默认this */
        // return m_age;
        return this->age;
    }
    /*1...当函数的形参与类的成员属性重名的情况下，this指针必须要写，来显示调用*/
    void setAge(int age)
    {
        this->age = age;
    }

private:
    int age;
};

class Mynumber
{
private:
    int n;

public:
    Mynumber() : n(0) {}
    Mynumber(int n) : n(n) {}
    /*2...设计函数返回对象本身*/
    Mynumber &add(int n)
    {
        this->n = this->n + n;
        return *this;
    }
    void printNum()
    {
        if (this == nullptr)
        {
            std::cout << "this为空\n";
        }
        /*this指针为空访问n的时候出现段错误*/
        std::cout << "num=" << n << std::endl;
    }
};
int main()
{
#if 0
    Person p1(5);
    Person p2(10);
    std::cout << p1.getAge() << std::endl;
    std::cout << p2.getAge() << std::endl;
#endif
    Mynumber number(2);
    number.printNum();
    number.add(3).add(4).add(7);
    number.printNum();
    Mynumber *number1=nullptr;
    number1->printNum();
}